package com.dididoctor.patient.Activity.Message.SystemMessage;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dididoctor.patient.MV.adapter.CommonAdapter;
import com.dididoctor.patient.MV.adapter.ViewHolder;
import com.dididoctor.patient.R;
import com.dididoctor.patient.Utils.LoaderImage;
import com.dididoctor.patient.Utils.SharedPreferencesUtils;
import com.dididoctor.patient.Utils.UserHeadImage;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import java.util.List;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： SystemMessageAdapter
 * @包名称： com.dididoctor.patient.Activity.Message.SystemMessage
 * @创建人： zhanjunjie
 * @创建时间：2016/4/14 17:10
 * @修改人：
 * @修改时间：2016/4/14 17:10
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class PersonalAdapter extends CommonAdapter<PersonalBean> {

    private UserHeadImage headImage;
    private Context context;
    private LoaderImage loaderImage;
    private TextView mTvDoctorName, mTvDoctorHot, mTvDoctorTime, mTvDoctorContent;
    private ImageView mImgMessageDot;
    private SystemMessagePresenter presenter;

    public PersonalAdapter(Context context, List<PersonalBean> datas,SystemMessagePresenter presenter) {
        super(context, datas, R.layout.item_system);
        this.context = context;
        this.presenter = presenter;
        loaderImage = new LoaderImage(context);
    }

    @Override
    public void convert(int position, ViewHolder helper, final PersonalBean item) {
        headImage = helper.getView(R.id.iv_head);
        loaderImage.load(headImage, item.getHeadPic(), new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {
                headImage.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {
                headImage.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });
        //姓名
        mTvDoctorName = helper.getView(R.id.tv_doctor_name);
        mTvDoctorName.setText(item.getName());
        //医院
        mTvDoctorHot = helper.getView(R.id.tv_doctor_hot);
        mTvDoctorHot.setText(item.getHospital());
        //时间
        mTvDoctorTime = helper.getView(R.id.tv_doctor_time);
        mTvDoctorTime.setText(item.getTime());
        //内容
        mTvDoctorContent = helper.getView(R.id.tv_doctor_content);
        mTvDoctorContent.setText("回复内容:" + item.getSuggestion());
        //红点
        mImgMessageDot = helper.getView(R.id.img_message_dot);
        if ("0".equals(item.getStatus())) {
            mImgMessageDot.setVisibility(View.VISIBLE);
        } else {
            mImgMessageDot.setVisibility(View.GONE);
        }

        helper.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = item.getName();
                String isSignDoctorid = SharedPreferencesUtils.getParam(context, "isSignDoctorid", "0");
                String issign = "0";
                if (isSignDoctorid.equals(item.getDoctorId())) {
                    issign = "1";
                } else {
                    issign = "0";
                }
                presenter.getgoAndFrom(item.getHospitalId(), item.getDoctorId(),item.getSessionId(), issign,name);
            }
        });
    }
}
